﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NaturalNote.Core.Database
{
    internal class Db : IDb
    {
        private DbTrait trait;        
        private IDbConnection con;       
        public Db(DbTrait trait, string connectionString)
        {
            this.trait = trait;            
            this.con = trait.GetConnection(connectionString);
        }

        public void Insert<T>(T row) where T : class, new()
        {
            DbWrapper<T>.Get(trait, con).Insert(row);            
        }

        public void Insert<T>(IEnumerable<T> row) where T : class, new()
        {
            DbWrapper<T>.Get(trait, con).Insert(row);
        }

        public void Save<T>(T row) where T : class, new()
        {
            DbWrapper<T>.Get(trait, con).Save(row);
        }

        public void Save<T>(IEnumerable<T> rows) where T : class, new()
        {
            DbWrapper<T>.Get(trait, con).Save(rows);
        }
    }
}
